package com.mdd.front.controller;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.mdd.common.core.AjaxResult;
import com.mdd.front.service.pay.IPayService;
import com.mdd.front.validate.PaymentValidate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/pay")
public class PayController {

    @Resource
    private IPayService iPayService;

    @PostMapping("/prePay")
    public AjaxResult prePay(@Validated(value = PaymentValidate.create.class)
                                 @RequestBody PaymentValidate paymentValidate) throws WxPayException {
        Object pay = iPayService.prePay(paymentValidate);
        return AjaxResult.success(pay);
    }
}
